/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.sql.Date;
import java.util.ArrayList;
import stuff.FDate;

/**
 *
 * @author JArik
 */
public class Item {
    private Date inDate;
    private Date dischargeDate;
    private String name;
    private String type;
    private String izmType;
    private double amount,maxAmount;
    private double buyPrice=-1, tax=-1;
    private double sellPrice=-1,payed=0;
    protected String currency;


    
    private String description;
    private Visit visit;
    private Distributor distributor;
    private double [] sellPrices;


    private int id, sklad_id, recId=0;
    private int distrId;
    private Doctor doctor;
    private Sklad sklad;
    private int disId=-1;

    public Item()
    {
        sellPrices = new double[3];
    }

    Item(int aInt, int aInt0, String string, Date date, Visit vis) {
        id = aInt;
        distrId = aInt0;
        name = string;
        inDate= date;
        visit = vis;
        doctor = vis.getExec();
    }
    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }
    public Doctor getExec() {
        return doctor;
    }
    public String getName()
    {
        if(name == null)
            return "Без имени";
        return name;
    }
    public Sklad getSklad() {
        return this.sklad;
    }
    public int getRecId() {
        return recId;
    }

    public void setRecId(int recId) {
        this.recId = recId;
    }

    public double getPayed() {
        return payed;
    }
    public void setPayed(double d)
    {
        payed = d;
    }

    public void setDisDate(Date dDate) {
        dischargeDate = dDate;
    }

    public void setInDate(Date disDate) {
        inDate = disDate;
    }
    public void setSklad(Sklad skl)
    {
        this.sklad = skl;
    }

    public void setAmount(double aInt) {
        amount = aInt;
    }

    public void setBuyPrice(double aDouble) {
        buyPrice = aDouble;
    }

    public void setDescr(String string) {
        description = string;
    }

    public void setDistributor(Distributor distr) {
        distributor = distr;
    }
    public void setId(int nId)
    {
        id = nId;
    }
    public void setName(String nName)
    {
        name = nName;
    }

    public void setSellPrice(double aDouble) {
        sellPrice = aDouble;
    }

    public void setType(String string) {
        type = string;
    }
    public String getType()
    {
        if(type == null)
            return "";
        return type;
    }
    public int getId()
    {
        return id;
    }
    public double getBuyPrice()
    {
        return buyPrice;
    }
    public double getSellPrice()
    {
        if(sellPrice == -1)
          return sellPrices[1];
        else
         return sellPrice;
    }
    public void setSellPrices(double price1, double price2, double price3)
    {
        sellPrices[0] = price1;
        sellPrices[1] = price2;
        sellPrices[2] = price3;
    }
    public double [] getSellPrices()
    {
        return sellPrices;
    }
    public double getAmount()
    {
        return amount;
    }
    public String getDescr()
    {
        if(description == null)
            return "";
        return description;
    }
    public Distributor getDist() {
        return distributor;
    }
    public Date getDisDate()
    {
        if(dischargeDate == null) return null;
        return new FDate(dischargeDate.getTime());
    }
    public Date getDisSQLDate()
    {
        if(dischargeDate == null) return null;
        return new Date(dischargeDate.getTime());
    }
    public Date getInDate() {
        if(inDate == null) return null;
        return new FDate(inDate.getTime());
    }
    public Date getInSQLDate()
    {
        if(inDate == null) return null;
        return new Date(this.getInDate().getTime());
    }
    public void setDisID(int dID)
    {
        disId = dID;
    }
    public int getDisID()
    {
        return disId;
    }
    public double getTax() {
        return tax;
    }

    public void setTax(double tax) {
        this.tax = tax;
    }
    public Doctor getDoctor() {
        return doctor;
    }

    public void setDoctor(Doctor doctor) {
        this.doctor = doctor;
    }
    public String toTableString()
    {
        return name;
    }
    public String getIzmType() {
        if(izmType == null)
            return "";
        return izmType;
    }
    public double getMaxAmount() {
        return maxAmount;
    }

    public void setMaxAmount(double maxAmount) {
        this.maxAmount = maxAmount;
    }
    public void setIzmType(String izmType) {
        this.izmType = izmType;
    }
    public String getNaming() {
        if(name == null)
                return "Вещь без названия";
            else if(type == null || type.equals(""))
                return name;
            else
                return ""+type+" "+name;
    }
    public String toString()
    {
        if(dischargeDate != null)
            return (name==null ? "Вещь без названия":getName());
        else if(sklad_id == 0)
            return getNaming();
        else // so sklada
            return "<html>"+getNaming() + " <i>[No-" + sklad_id + "Скл.-"+ sklad.getName() +
                                           " ("+inDate.toString()+ ")]</i></html>";
    }

}
